{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "19518a0f-475e-462d-a41e-2a17d3b19b12",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "list= [9, 7, 8, 3, 2, 1, 55, 6]\n",
      "最大值= 55 ,最小值= 1 ,元素个数= 8\n",
      "list= ['apple', 'pear', 'melon', 'kiwi']\n",
      "最大值= pear ,最小值= apple ,元素个数= 4\n",
      "list= TheQuickBrownFox\n",
      "最大值= x ,最小值= B ,元素个数= 16\n",
      "list= (9, 7, 8, 3, 2, 1, 55, 6)\n",
      "最大值= 55 ,最小值= 1 ,元素个数= 8\n"
     ]
    }
   ],
   "source": [
    "#求序列类型的最大值和最小值\n",
    "def getMaxMin(s):\n",
    "    maxi  = s[0]\n",
    "    mini  = s[0]\n",
    "    for i in range( 0, len(s)):\n",
    "        if maxi<s[i]:\n",
    "            maxi = s[i]\n",
    "        if mini>s[i]:\n",
    "            mini = s[i]\n",
    "    return maxi,mini,len(s)\n",
    "#测试代码\n",
    "list1=[9,7,8,3,2,1,55,6]\n",
    "x1,y1,z1 = getMaxMin(list1)\n",
    "print(\"list=\", list1)\n",
    "print(\"最大值=\",x1, \",最小值=\", y1, \",元素个数=\", z1)\n",
    "\n",
    "list2=[\"apple\",\"pear\",\"melon\",\"kiwi\"]\n",
    "x2,y2,z2 = getMaxMin(list2)\n",
    "print(\"list=\", list2)\n",
    "print(\"最大值=\",x2, \",最小值=\", y2, \",元素个数=\", z2)\n",
    "\n",
    "list3=\"TheQuickBrownFox\"\n",
    "x3,y3,z3 = getMaxMin(list3)\n",
    "print(\"list=\", list3)\n",
    "print(\"最大值=\",x3, \",最小值=\", y3, \",元素个数=\", z3)\n",
    "\n",
    "list4=(9,7,8,3,2,1,55,6)\n",
    "x4,y4,z4 = getMaxMin(list4)\n",
    "print(\"list=\", list4)\n",
    "print(\"最大值=\",x4, \",最小值=\", y4, \",元素个数=\", z4)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5fd57d9a-34ec-4c6e-bf3a-7ddd53756171",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
